<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 14-2-7
 * Time: 下午9:06
 */

class OddsmanageController extends Controller{

    public function index() {
        $this->getSmarty ();
        require_once SERVICE . DS . 'admin' . DS . 'event' . DS . 'IboEvent.class.php';
        require_once SERVICE . DS . 'admin' . DS . 'event' . DS . 'Page.class.php';
        //赛事名称
        if(array_key_exists('sport_subtype_name', $_GET)){
            $sport_subtype_name = $_GET['sport_subtype_name'];
        }

//队名
        if(array_key_exists('team_name', $_GET)){
            $team_name = $_GET['team_name'];
        }

//比赛起始时间
        if(array_key_exists('starttime', $_GET)){
            $starttime = $_GET['starttime'];
        }

//比赛结束时间
        if(array_key_exists('endtime', $_GET)){
            $endtime = $_GET['endtime'];
        }
        $conditionArr = array();
        if($sport_subtype_name!=null){
            $conditionArr['sport_subtype_name'] = $sport_subtype_name;
        }
        if($team_name!=null){
            $conditionArr['team_name'] = $team_name;
        }
        if($starttime!=null){
            $conditionArr['starttime'] = $starttime;
        }
        if($endtime!=null){
            $conditionArr['endtime'] = $endtime;
        }

        if(array_key_exists('type', $_GET)){
            $type = $_GET['type'];
        }else{
            $type = "current";
        }

        if(array_key_exists('pageNo', $_GET)){
            $pageNo = $_GET['pageNo'];
        }else{
            $pageNo = 1;
        }

        $iboEvent = new IboEvent($this->getDB () );

        $events = null;

        if($type=='current'){
            //查询当前赛事
//	$events = $iboEvent->getAllEvent($sport_subtype_name,$team_name,$starttime,$endtime);
            $events = $iboEvent->getAllEvent($conditionArr);
        }elseif ($type=='history'){
            //查询比赛结束赛事
            $page = new Page($pageNo);
            $events = $iboEvent->getAllFinishedEvent($conditionArr,$page)->result;
            $page->result = null;
        }else{
            $events = $iboEvent->getHistoryeventWithNoScore();
        }
        $this->smarty->assign("eventcurrentnav",$type);
        $this->smarty->assign("currentnav" , "oddsmanage");
        $this->smarty->assign("events",$events);
        $this->smarty->assign("page",$page);

        $maxdisplaypageNum = 5;
        if($page->totalpage<=5){
            $startPage = 1;
            $endPage = $page->totalpage;
        }else{
            if($page->pageNo>(int)$maxdisplaypageNum/2+1){
                if($page->pageNo+2<$page->totalpage){
                    $startPage = $page->pageNo-2;
                    $endPage = $page->pageNo+2;
                }else{
                    $startPage = $page->totalpage-$maxdisplaypageNum+1;
                    $endPage = $page->totalpage;
                }
            }else{
                $startPage = 1;
                if($page->totalpage>5){
                    $endPage = $maxdisplaypageNum;
                }else{
                    $endPage = $page->totalpage;
                }
            }
        }
        $this->smarty->assign("startPage",$startPage);
        $this->smarty->assign("endPage",$endPage);


        $this->smarty->assign("modulename","赛事管理首页");
        $this->smarty->display("admin/event/oddsmanage.tpl");
    }
}

?>